import { reqGetSearchInfo } from "@/api";
import Cache from '../../utils/cache'
const state = {
  searchList: {}
};
const mutations = {
  GETSEARCHLIST(state, searchList) {
    state.searchList = searchList
  }
};
const actions = {
  async getSearchList({ commit }, params = {}) {
    let Cachedata = Cache.get(params);

    if (Cachedata === null) {
      let result = await reqGetSearchInfo(params);
      // console.log(result);
      if (result.code === 200) {
        commit("GETSEARCHLIST", result.data)
        console.log(result.data);

        Cache.set(params, result.data)
      }
    }
    else {
      // console.log(123777);
      commit("GETSEARCHLIST", Cachedata)
    }
  }
};
const getters = {//为简化数据而生
  goodsList(state) {//当前仓库的state
    return state.searchList.goodsList || {}
  },
  trademarkList(state) {
    return state.searchList.trademarkList
  },
  attrsList(state) {
    return state.searchList.attrsList
  }
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}